
const { app, BrowserWindow, ipcMain } = require("electron");
const path = require('path');
const ipcEvent = require('./ipcEvent')
// 热加载
try {
  require('electron-reloader')(module,{});
} catch (_) {}

let mainWindow; app.allowRendererProcessReuse = false;
// 创建窗口
function createWindow() {
  mainWindow = new BrowserWindow({
    minWidth: 900,
    minHeight: 700,
    frame: false,
    icon: './ico/app.ico',
    backgroundColor: "#929292",
    webPreferences: {
      nodeIntegration: true,
      webSecurity: false,
      enableRemoteModule: true,
      nodeIntegrationInWorker: true,
      // preload: path.join(__dirname, 'preload.js')
    },
  });
  mainWindow.center()
  mainWindow.removeMenu()
  mainWindow.loadFile("./src/index.html/");
  // 订阅事件
  ipcEvent(ipcMain, mainWindow)
  mainWindow.on("closed", function () {
    mainWindow = null;
  });  
}
// 启动
app.on("ready", createWindow);

// 关闭
app.on("window-all-closed", function () {
  if (process.platform !== "darwin") app.quit();
});

// 重启
app.on("activate", function () {
  if (mainWindow === null) createWindow();
});